//
//  XYPageView.swift
//  XMGTV
//
//  Created by Gary on 2018/3/8.
//  Copyright © 2018年 coderwhy. All rights reserved.
//

import UIKit


class XYPageView: UIView {
    
    fileprivate var titles : [String]
    fileprivate var childVcs : [UIViewController]
    fileprivate var parentVC :UIViewController
    fileprivate var attribute :XYPageAttribute
    
    var titlePageView : XYTitlePageView!
    
    init(frame: CGRect, titles : [String], childVcs : [UIViewController] , parentVC:UIViewController ,attribute:XYPageAttribute) {
        
        self.titles = titles
        self.childVcs = childVcs
        self.parentVC = parentVC
        self.attribute = attribute
        
        super.init(frame: frame)
        
        //创建 UI
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}

// MARK:- 创建UI extension
extension XYPageView {
    
    fileprivate func setupUI() {
        setupTitlePageView()
        setupContentPageView()
    }
    
    private func setupTitlePageView() {
        
        let frame = CGRect(x: 0.0, y: 0.0, width: bounds.width, height: attribute.titleHeight)
        titlePageView = XYTitlePageView(frame: frame, titles: titles, attribute: attribute)
        addSubview(titlePageView)
        
    }
    
    private func setupContentPageView() {
        let frame = CGRect(x: 0.0, y: self.attribute.titleHeight, width: bounds.width, height: bounds.height-self.attribute.titleHeight)
        let contentPageView = XYContentPageView(frame: frame, childVcs: self.childVcs, parentVC: self.parentVC)
        addSubview(contentPageView)
        
        titlePageView.delegate = contentPageView

    }
    
}


